#include <buola/gui.h>

#include <buola/algorithm/comparison.h>

#include <buola/gui/cconfig.h>
#include <buola/widgets/ctheme.h>

#include <buola/widgets/cprogressbar.h>

namespace buola { namespace gui {

CProgressBar::CProgressBar()
{
    SetStyle(LBL_BOTTOM|LBL_LEFT);
    mProgress=0;
    SetBackColor(gConfig.mColors.Get(L"normal_back"));
}

CProgressBar::~CProgressBar()
{
}

void CProgressBar::GetPropertyNames(std::vector<std::string> &pNames)
{
    pNames.push_back("value");

    CWidget::GetPropertyNames(pNames);
}

void CProgressBar::SetProperty(const std::string &p,const UAny &v)
{
    if(iequals(p,"value"))
    {
        SetProgress(v.Get<int>());
    }
    else
    {
        CWidget::SetProperty(p,v);
    }
}

void CProgressBar::SetProgress(double pProgress)
{
    mProgress=pProgress;
    Refresh();
}

void CProgressBar::SetProgress(int pNum,int pMax)
{
    mProgress=double(pNum)/double(pMax);
    Refresh();
}

///////////////////// Event handling //////////////////////

void CProgressBar::OnExpose(const CExposeEvent &pE)
{
    get_default_theme()->DrawProgressBar(pE.mGC,this,CTheme::DRAW_NONE);
}

void CProgressBar::OnSize(const CGeometryEvent &pE)
{
}

/*namespace gui*/ } /*namespace buola*/ }
